﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QianJin.Models
{
    public class ShoppingCart
    {
        public IList<ProductDatabaseProduct> ShoppingItems { get; private set; }

        public ShoppingCart()
        {
            ShoppingItems = new List<ProductDatabaseProduct>();
        }

        public ProductDatabaseProduct AddProduct(string id)
        {
            var prod = ProductDatabase.Instance.GetProduct(id);

            if (!ShoppingItems.Contains(prod))
            {
                ShoppingItems.Add(prod);
            }

            return prod;
        }

        public ProductDatabaseProduct RemoveProduct(string id)
        {
            var prod = ProductDatabase.Instance.GetProduct(id);

            ShoppingItems.Remove(prod);

            return prod;
        }

        public bool IsProductAdded(string id)
        {
            return ShoppingItems.Where(
                prod => { return id.Equals(prod.id, StringComparison.OrdinalIgnoreCase); }).Count() > 0;
        }
    }
}
